/**
 * @file: vscode
 * @author: v_xieyejiang
 * @Date: 2018-12-10 11:21:06
 * @Last Modified by: v_xieyejiang
 * @Last Modified time: 2018-12-10 14:58:09
 */

import Vue from 'vue';
import Vuex from 'vuex';

import * as types from '@/store/mutation-types';
import {utilsAxios} from '@/utils';
import user from '@/services/node/user';
import hello from './module/hello';
import notice from './module/notice';

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        appUser: {}
    },
    getters: {
        appUser: State => State.appUser
    },
    actions: {
        async getUser({commit}, options) {
            const result = await user.getUser(options && options.data);
            utilsAxios(options, result);
            if (result && result.data && result.data.data) {
                commit(types.USER, result.data.data);
            }
        },
        async logout({commit}, options) {
            await user.logout(options && options.data);
        }
    },
    mutations: {
        [types.USER](State, data) {
            State.appUser = data;
        }
    },
    modules: {
        hello,
        notice
    }
});
